<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>百度地图-标注点、点击事件</title>
<script src="../js/baidu_map.js" type="text/javascript"></script>
<script src="../js/jquery-2.0.3.min.js" type="text/javascript"></script>
</head>
<body>
	<div id="map_container" style="height: 100px; width: 100px%;"></div>
</body>
</html>
<script type="text/javascript">
	var mapInst = null;
	//数据准备
	var points = [ {
		"lng" : 116,
		"lat" : 40,
		"url" : "http://www.baidu.com",
		"id" : 50,
		"name" : "p1"
	}, {
		"lng" : 117,
		"lat" : 31,
		"url" : "http://www.taobao.com",
		"id" : 2,
		"name" : "p2"
	}, {
		"lng" : 116,
		"lat" : 34,
		"url" : "http://www.qq.com",
		"id" : 3,
		"name" : "p3"
	} ];

	function map_init() {
		if (null == mapInst) {
			mapInst = baiduMapInit("map_container", [ 114.3302930161,
					30.6058626248 ], 6, "中国", "");
		}
		addMarker(mapInst, points);
	}
	function addMarker(mapInst, points) { // 创建图标对象   
		var point, marker;
		// 创建标注对象并添加到地图   
		for (var i = 0, pointsLen = points.length; i < pointsLen; i++) {
			point = new BMap.Point(points[i].lng, points[i].lat);
			marker = new BMap.Marker(point);
			mapInst.addOverlay(marker);
			//给标注点添加点击事件。使用立即执行函数和闭包
			(function() {
				var thePoint = points[i];
				marker.addEventListener("click", function() {
					showInfo(this, thePoint);
				});
			})();
		}
	}
	//显示信息窗口，显示标注点的信息。
	function showInfo(thisMaker, point) {
		var sContent = '<ul class="info_ul">'
				+ '<li class="info_li">'
				+ '<span class="info_span">id：</span>'
				+ point.id
				+ '</li>'
				+ '<li class="info_li">'
				+ '<span class="info_span">名称：</span>'
				+ point.name
				+ '</li>'
				+ '<li class="info_li"><span class="info_span">查看：</span><a href="'+point.url+'" target="_blank">详情</a></li>'
				+ '</ul>';
		var infoWindow = new BMap.InfoWindow(sContent);// 创建信息窗口对象
		thisMaker.openInfoWindow(infoWindow);//图片加载完毕重绘infowindow
	}
	$().ready(function() {
		$("#map_container").height($(document).height() - 18);
		loadBaiduScript("map_init");
	});
</script>